home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 43.zip / Sources C- WorkDisk III.adf / double1.c < prev    next >
C/C++ Source or Header  |  1986-11-30  |  5KB  |  219 lines

  1. #include "exec/types.h"
  2. #include "exec/exec.h"
  3. #include "graphics/gfx.h"
  4. #include "graphics/gfxmacros.h"
  5. #include "graphics/copper.h"
  6. #include "graphics/view.h"
  7. #include "graphics/regions.h"
  8. #include "graphics/clip.h"
  9. #include "graphics/gfxbase.h"
  10. #include "graphics/rastport.h"
  11. #include "hardware/custom.h"
  12. #include "hardware/dmabits.h"
  13.  
  14. #define DEPTH 4
  15. #define COLORS 16
  16. #define WIDTH 320
  17. #define HEIGHT 200
  18. #define NOT_ENOUGH_MEMORY -1000
  19.  
  20. extern struct Custom custom;
  21. struct View v;
  22. struct ViewPort vp;
  23. struct ColorMap *cm;
  24. struct RasInfo ri;
  25. struct BitMap b;
  26. struct BitMap b2;
  27. struct cprlist *lof1;
  28. struct cprlist *lof2;
  29. struct cprlist *shf1;
  30. struct cprlist *shf2;
  31. struct CopList *Disp1, *Disp2;
  32.  
  33. PLANEPTR rastpoint, rastpoint2;
  34.  
  35. struct RastPort rp;
  36. struct RastPort rp2;
  37.  
  38. WORD areabuffer[250];
  39. struct TmpRas tmpras;
  40. struct AreaInfo myAreaInfo;
  41.  
  42. WORD areabuffer2[250];
  43. struct TmpRas tmpras2;
  44. struct AreaInfo myAreaInfo2;
  45.  
  46.  
  47. extern struct ColorMap *GetColorMap() ;
  48. struct GxfBase *GfxBase;
  49. struct View *oldview;
  50.  
  51. USHORT colortable[COLORS] = { 0x000, 0x222, 0x444, 0x555, 0x666, 0x777,
  52.        0x888, 0x999, 0xaaa, 0xbbb, 0xccc, 0xddd, 0xeee, 0xfff, 0x005, 0x00a };
  53.  
  54. UBYTE *displaymem;
  55. UWORD *colorpalette;
  56.  
  57. /* ------------------------------------------------------------------------- */
  58.  
  59. main()
  60. {
  61.  
  62.  LONG i;
  63.  SHORT x;
  64.  
  65.  /* ---------------- end of declarations ----------------------------------- */
  66.  
  67.  GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0);
  68.  if(GfxBase == NULL) exit(1);
  69.  
  70.  oldview = GfxBase->ActiView;
  71.  
  72.  OFF_SPRITE;
  73.  InitView(&v);              /* init view */
  74.  InitVPort(&vp);            /* init ViewPort */
  75.  v.ViewPort = &vp;          /* link viewport into view */
  76.  
  77.  InitBitMap(&b , DEPTH, WIDTH, HEIGHT); /* init bitmap voor RasInfo & RastPort */
  78.  InitBitMap(&b2, DEPTH, WIDTH, HEIGHT); /* double buffering */
  79.  
  80.  ri.BitMap = &b;            /* init RasInfo */
  81.  ri.RxOffSet = 0;
  82.  ri.RyOffset = 0;
  83.  ri.Next = NULL;
  84.  
  85.  vp.DWidth = WIDTH;         /* specifieren van viewport karakteristieken */
  86.  vp.DHeight = HEIGHT;
  87.  vp.RasInfo = &ri;
  88.  
  89.  cm = GetColorMap(COLORS);  /* init colortable */
  90.  vp.ColorMap = cm;          /* Set viewport pointer naar mijn kleuren */
  91.  LoadRGB4(&vp, colortable, COLORS); /* Set de viewport kleuren */
  92.  
  93.  for(i=0; i<DEPTH; i++) /* Allocate RAM for bitmaps */
  94.  {
  95.   b.Planes[i] = (PLANEPTR)AllocRaster(WIDTH, HEIGHT);
  96.   if(b.Planes[i] == NULL) exit(NOT_ENOUGH_MEMORY);
  97.   b2.Planes[i] = (PLANEPTR)AllocRaster(WIDTH, HEIGHT);
  98.   if(b2.Planes[i] == NULL) exit(NOT_ENOUGH_MEMORY);
  99.  }
  100.  
  101.  ri.BitMap = &b; 
  102.  MakeVPort(&v,&vp); /* maak copper instruct list */
  103.  MrgCop(&v);  /* merge prelim lists samen tot een echte copper list */
  104.               /* in the view structure */
  105.  lof1 = v.LOFCprList;      /* long frame */
  106.  shf1 = v.SHFCprList;      /* short frame */
  107.  Disp1 = v.ViewPort->DspIns; /* zorg dat colormap */
  108.                              /* op correcte manier verandert */
  109.  v.LOFCprList = 0;
  110.  v.SHFCprList = 0;
  111.  v.ViewPort->DspIns = 0;
  112.  
  113.  ri.BitMap = &b2; 
  114.  MakeVPort(&v,&vp); /* maak copper instruct list */
  115.  MrgCop(&v);  /* merge prelim lists samen tot een echte copper list */
  116.               /* in the view structure */
  117.  lof2 = v.LOFCprList;      /* store pointers to copper lists voor bitmap 2 */
  118.  shf2 = v.SHFCprList;      
  119.  Disp2 = v.ViewPort->DspIns; /* zorg dat colormap */
  120.                              /* op correcte manier verandert */
  121.  
  122.  LoadView(&v); /* nu gebruikt de copper de list voor display */ 
  123.  
  124.  InitRastPort(&rp);
  125.  rp.BitMap = &b;
  126.  SetDrMd(&rp, JAM1);
  127.  
  128.  InitArea(&myAreaInfo,areabuffer, 100);
  129.  rp.AreaInfo = &myAreaInfo;
  130.  
  131.  rastpoint = (PLANEPTR)AllocRaster(WIDTH, HEIGHT);
  132.  InitTmpRas(&tmpras,rastpoint, RASSIZE(WIDTH,HEIGHT));
  133.  rp.TmpRas = &tmpras;
  134.  
  135.  
  136.  InitRastPort(&rp2);
  137.  rp2.BitMap = &b2;
  138.  SetDrMd(&rp2, JAM1);
  139.  
  140.  InitArea(&myAreaInfo2,areabuffer2, 100);
  141.  rp2.AreaInfo = &myAreaInfo2;
  142.  
  143.  rastpoint2 = (PLANEPTR)AllocRaster(WIDTH, HEIGHT);
  144.  InitTmpRas(&tmpras2,rastpoint2, RASSIZE(WIDTH,HEIGHT));
  145.  rp2.TmpRas = &tmpras2;
  146.  
  147.  SetOPen(&rp,0);
  148.  SetOPen(&rp2,0);
  149.  
  150.  SetRast(&rp,0);
  151.  SetRast(&rp2,0);
  152.  
  153.  for(x=0; x<25; x++)
  154.  {
  155.  
  156.   v.LOFCprList = lof1;
  157.   v.SHFCprList = shf1;
  158.   v.ViewPort->DspIns = Disp1;
  159.   WaitBOVP(&vp);
  160.   LoadView(&v);
  161.   SetAPen(&rp,3);
  162.   for(i=0; i<HEIGHT; i+=4)
  163.   {
  164.    Move(&rp,0,i);Draw(&rp,WIDTH-1,i);
  165.   }
  166.  
  167.   v.LOFCprList = lof2;
  168.   v.SHFCprList = shf2;
  169.   v.ViewPort->DspIns = Disp2;
  170.   WaitBOVP(&vp);
  171.   LoadView(&v);
  172.   SetAPen(&rp,9);
  173.   for(i=2; i<HEIGHT; i+=4)
  174.   {
  175.    Move(&rp2,0,i);Draw(&rp2,WIDTH-1,i);
  176.   }
  177.  
  178.  }
  179.  
  180.  ON_SPRITE;
  181.  LoadView(oldview);
  182.  FreeMemory();
  183.  CloseLibrary(GfxBase);
  184. }
  185.  
  186. FreeMemory()
  187. {
  188.  int i;
  189.  
  190.  FreeRaster(rastpoint,WIDTH, HEIGHT);
  191.  FreeRaster(rastpoint2,WIDTH, HEIGHT);
  192.  
  193.  for(i=0;i<DEPTH; i++)
  194.  {
  195.   FreeRaster(b.Planes[i],WIDTH, HEIGHT);
  196.   FreeRaster(b2.Planes[i],WIDTH, HEIGHT);
  197.  }
  198.  
  199.  FreeColorMap(cm);
  200.  v.LOFCprList = lof1;
  201.  v.SHFCprList = shf1;
  202.  FreeVPortCopLists(&vp);
  203.  FreeCprList(v.LOFCprList);
  204.  FreeCprList(v.SHFCprList);
  205.  v.LOFCprList = lof2;
  206.  v.SHFCprList = shf2;
  207.  FreeVPortCopLists(&vp);
  208.  FreeCprList(v.LOFCprList);
  209.  FreeCprList(v.SHFCprList);
  210.  return(0);
  211.  
  212. }
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.